package com.skyline.demo.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.skyline.common.bean.Page;

@Controller
public class PageDemo {
	@RequestMapping("/page")
	public ModelAndView page(Page page, HttpServletRequest request) {
		page.setSize(50);
		page.setTotal(251);//由数据库做
		request.setAttribute("pager", page);
		return new ModelAndView("/demo/pagination");
	}
	
	@RequestMapping("ajaxPage1")
	public @ResponseBody Map<String, Object> ajaxPage1(Page page) {
		page.setSize(6);
		page.setTotal(62);//由数据库做
		Map<String, Object> map = new HashMap<String, Object>();
		List<String> otherThing = new ArrayList<String>();
		//otherThing.add("1");
		//otherThing.add("5");
		//otherThing.add("7");
		int curpage=page.getCurpage();
		otherThing.add(String.valueOf(curpage));
		otherThing.add(String.valueOf(curpage+1));
		otherThing.add(String.valueOf(curpage+2));
		map.put("page", page);
		map.put("data", otherThing);
		return map;
	}
	
	@RequestMapping("ajaxPage2")
	public @ResponseBody Map<String, Object> ajaxPage2(Page page) {
		page.setSize(6);
		page.setTotal(73);//由数据库做
		Map<String, Object> map = new HashMap<String, Object>();
		List<String> otherThing = new ArrayList<String>();
		otherThing.add("2");
		otherThing.add("6");
		otherThing.add("8");
		map.put("page", page);
		map.put("data", otherThing);
		return map;
	}
}
